 
 import { unioformDateTransform } from "@/utils/index.js";

 export function createTask(db){
    // 创建 task 数据库表
    let objectStore;
    if(!db.objectStoreNames.contains('task')){
        // 自动生成主键 ---新增的时候，必须要指定绑定的键
        objectStore = db.createObjectStore('task',{autoIncreament:true})
        // 创建表字段   //索引名称，索引所在属性，配置对象
        objectStore.createIndex('id','id',{unique:true})
        objectStore.createIndex('taskName','taskName',{unique:true})
        objectStore.createIndex('startTime','startTime',{unique:false})
        objectStore.createIndex('endTime','endTime',{unique:false})
        objectStore.createIndex('createDate','createDate',{unique:false})
        objectStore.createIndex('isAlarmClock','isAlarmClock',{unique:false})
        objectStore.createIndex('isUrgency','isUrgency',{unique:false})

        // 只在建表时插入初始数据
        objectStore.add({
            taskName:"任务1",
            startTime:"10:00",
            endTime:"11:00",
            createDate:unioformDateTransform(new Date()),
            isAlarmClock:false,
            isUrgency:false
        },"id");
    }
}

